package com.yuan.base.service.server;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;

import java.util.Arrays;

/**
 * 统一为服务启动类，便于扩展
 *
 * @author lintiangang
 * @date 2021/03/26 10:12
 **/
@Slf4j
@ComponentScan(basePackages = {"com.yuan"})
@EnableFeignClients(basePackages = {"com.yuan"})
@EnableDiscoveryClient
public class MuruiMicroService {
    public ApplicationContext start(String[] args) {

        loadDefaultSpringConfig();

        SpringApplication springApplication = new SpringApplication(MuruiMicroService.class);
        springApplication.setBannerMode(Banner.Mode.CONSOLE);


//        springApplication.addListeners();
        ApplicationContext ctx = springApplication.run(args);

        String[] beanNames = ctx.getBeanDefinitionNames();
        log.debug("Let's inspect the beans provided by Spring Boot， total {} beans:", beanNames.length);
        Arrays.sort(beanNames);
        for (String beanName : beanNames) {
            log.debug(beanName);
        }

        return ctx;
    }

    private void loadDefaultSpringConfig() {

//        System.setProperty("feign.sentinel.enabled", "true");
//
//        System.setProperty("management.endpoints.exposure.include", "*");
//        System.setProperty("management.health.sentinel.enabled", "false");
//        System.setProperty("spring.cloud.consul.discovery.register", "true");
//        System.setProperty("spring.cloud.consul.discovery.healthCheckPath", "/actuator/health");
//        System.setProperty("spring.cloud.consul.discovery.preferIpAddress","true");
//
//        System.setProperty("spring.cloud.consul.discovery.healthCheckInterval", "15s");
//        System.setProperty("spring.cloud.consul.discovery.healthCheckCriticalTimeout", "45s");
    }
}
